package com.yzr.helloworld;

import com.rabbitmq.client.*;
import com.yzr.util.RabbitMqClient;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitMqClient.getConnection();

        Channel channel = connection.createChannel();

        channel.queueDeclare("hello-world", true, false, false, null);

        channel.basicConsume("hello-world", true, new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费消息：" + new String(body));
            }
        });

    }
}
